What's the best algorithm for... [closed]

Posted by Paska on Programmers See other posts from Programmers or by Paska
Published on 2011-01-17T20:23:09Z Indexed on 2011/01/17 21:00 UTC
Read the original article Hit count: 347

Hi programmers!
Today come out a little problem.

I have an array of coordinates (latitude and longitude) maded in this way:

[0] = "45.01234,9.12345"
[1] = "46.11111,9.12345"
[2] = "47.22222,9.98765"
[...] etc

In a loop, convert these coordinates in meters (UTM northing / UTM easting) and after that i convert these coords in pixel (X / Y) on screen (the output device is an iphone) to draw a route line on a custom map.

[0] = "512335.00000,502333.666666"
[...] etc

The returning pixel are passed to a method that draw a line on screen (simulating a route calculation).

[0] = "20,30"
[1] = "21,31"
[2] = "25,40"
[...] etc

As coordinate (lat/lon) are too many, i need to truncate lat/lon array eliminating the values that doesn't fill in the map bound (the visible part of map on screen).
Map bounds are 2 couple of coords lat/lon, upper left and lower right.

Now, what is the best way to loop on this array (NOT SORTED) and check if a value is or not in bound and after remove the value that is outside?
To return a clean array that contains only the coords visible on screen?

Note: the coords array is a very big array. 4000/5000 couple of items.
This is a method that should be looped every drag or zoom.

Anyone have an idea to optimize search and controls in this array?

many thanks,
A

© Programmers or respective owner

Related posts about programming

Related posts about programming-practices